<template>
  <div class="name-popupbox">
    <!-- 导航 -->
    <van-nav-bar
      title="标题"
      left-text="取消"
      right-text="完成"
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <div class="text">
      <van-field
        v-model="message"
        rows="2"
        autosize
        type="textarea"
        maxlength="7"
        placeholder="请输入名称"
        show-word-limit
      />
    </div>
  </div>
</template>

<script>
import { updateProfile } from "@/api/axios";
export default {
  name: "name-popupbox",
  data() {
    return {
      message: this.name,
    };
  },
  props: {
    name: {
      type: String,
      required: true,
    },
  },
  methods: {
    onClickLeft() {
      this.$emit("close");
    },
    async onClickRight() {
      this.$toast.loading({
        message: "修改中...",
        forbidClick: true,
      });
      // 发送请求---修改用户名
      try {
        const { data: res } = await updateProfile({ name: this.message });
        //   修改成功
        this.$toast.success("修改成功");
        // 1.关闭弹框
        // 2.手动修改用户昵称
        this.$emit('close',this.message)
        
      } catch (err) {

        console.log(err);
      }
    },
  },
  created() {},
};
</script>

<style lang='less' scoped>
.name-popupbox {
  .text {
    padding: 15px 30px;
  }
}
</style>